package com.objetdirect.gwt.umldrawer.client;

import com.gwtext.client.core.EventObject;
import com.gwtext.client.core.Position;
import com.gwtext.client.data.SimpleStore;
import com.gwtext.client.data.Store;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.MessageBox;
import com.gwtext.client.widgets.Window;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
import com.gwtext.client.widgets.form.ComboBox;
import com.gwtext.client.widgets.form.FormPanel;
import com.gwtext.client.widgets.layout.FitLayout;

public class EditMemberPrivilegeWindow extends Window {

	public EditMemberPrivilegeWindow() {
		
		this.setTitle("Edit Member");
		this.setWidth(500);
		this.setHeight(100);
		this.setLayout(new FitLayout());
		this.setPaddings(5);
		this.setButtonAlign(Position.CENTER);

		Button editButton = new Button("Edit Member");
		this.addButton(editButton);

		ButtonListenerAdapter editButtonAdapter = new ButtonListenerAdapter() {
			@Override
			public void onClick(Button button, EventObject e) {
				MessageBox.alert("Server Info",
						"That Member Has Been Edited!");
				hide();
			}
		};
		editButton.addListener(editButtonAdapter);

		Button cancelButton = new Button("Cancel");
		this.addButton(cancelButton);

		ButtonListenerAdapter cancelButtonAdapter = new ButtonListenerAdapter() {
			@Override
			public void onClick(Button button, EventObject e) {
				hide();
			}
		};
		cancelButton.addListener(cancelButtonAdapter);

		this.setCloseAction(Window.HIDE);
		this.setPlain(true);
		this.setModal(true);

		FormPanel formPanel = new FormPanel();
		formPanel.setBaseCls("x-plain");
		formPanel.setLabelWidth(100);
		formPanel.setUrl("save-form.php");

		formPanel.setWidth(500);
		formPanel.setHeight(100);

		final Store store = new SimpleStore(new String[] {"privilege"}, getStates());
		store.load();

		ComboBox privilege = new ComboBox("Member Privilege", "privilage", 300);
		privilege.setEmptyText("Privilege");
		privilege.setForceSelection(true);
		privilege.setDisplayField("privilege");
		privilege.setMode(ComboBox.LOCAL);
		privilege.setTriggerAction(ComboBox.ALL);
		privilege.setTypeAhead(true);
		privilege.setSelectOnFocus(true);
		privilege.setStore(store);
		formPanel.add(privilege);

		this.add(formPanel);
		this.show();
	}
	
	private static String[][] getStates() {  
        return new String[][]{  
                new String[]{"Read Only"},
                new String[]{"Read / Write"}
                };
}
}
